package main

import (
	"deploy/interfaces"
	db "deploy/interfaces/db"
	"deploy/utils"
	"log"
	"os"
)

var Conf *utils.ServerConf
var DB db.MysqlStruct
var FuncS []string
func init() {
	utils.DataYaml = "etc/data.yaml"
	log.Println("启动中...")
	var err error
	Conf,err = utils.GetServerConfiguration("etc/server.yaml")
	if err !=nil{
		log.Println("加载配置出错",err.Error())
		os.Exit(0)
	}
	log.Println("配置加载成功")
	interfaces.WhiteList=Conf.WhiteList
	mysql := Conf.MysqlConf
	DB = db.NewMysqlStruct(mysql.User,mysql.Passwd,mysql.Host,mysql.DbName,mysql.Port)
	err = DB.GetDB()
	if err != nil{
		log.Println("数据库连接出错",err.Error())
		os.Exit(0)
	}
	log.Println("数据库连接成功")
	FuncS = utils.SF.Funcs()
	log.Println("agent命令集合加载成功")
	//  把所有实例置为不在线，等他再上报
	err=DB.SetOffline()
	if err!=nil{
		log.Println("重置实例状态失败：",err.Error())
		os.Exit(0)
	}
	log.Println("设置所有实例状态为不在线，ok")
}

func main(){
	server:= interfaces.NewServer(Conf,&DB)
	server.Start()
}